package business.response;

import static common.Constant.CONTNO;
import static common.Constant.RATE;
import static common.Constant.TASK;

import java.util.Map;
import java.util.TimerTask;

import common.util.JsonUtil;
import redis.clients.jedis.Jedis;

public class MonitorTask extends TimerTask implements Runnable {
    Jedis mJedis = null;

    public MonitorTask(Jedis mJedis) {
        this.mJedis = mJedis;
    }

    @Override
    public void run() {
        String tJson = mJedis.rpop(TASK);
        if (tJson == null) {
            return;
        }
        Map<String, Object> tMap = JsonUtil.getMapObject(tJson);
        System.out.println(tMap.get(CONTNO) + " " + tMap.get(RATE));
        try {
            Thread.sleep((long) (Math.random() * 100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
